﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using AzureDiagMon.Common.Algorithms.FragmentedRanges;
using AzureDiagMon.Common.Dtos;
using AzureDiagMon.Common.Interfaces;
using AzureDiagMon.Model;

namespace AzureDiagMon.Services.Mappings
{
    public class WadLogDownloadedSectionsMapCreator : IMapCreator
    {
        #region Implementation of IMapCreator

        public void CreateMap(IProfileExpression mapper)
        {
            mapper.CreateMap<WadLogDownloadedSection, WadLogDownloadedSectionDto>();
            mapper.CreateMap<WadLogDownloadedSection, FragmentedRangeSection<long>>()
                .ForMember(d => d.StartIndex, f => f.MapFrom(s => s.StartKey))
                .ForMember(d => d.EndIndex, f => f.MapFrom(s => s.EndKey));
            mapper.CreateMap<WadLogDownloadedSection, LoadedRangeSection<long>>()
                .ForMember(d => d.StartIndex, f => f.MapFrom(s => s.StartKey))
                .ForMember(d => d.EndIndex, f => f.MapFrom(s => s.EndKey));
            mapper.CreateMap<FragmentedRangeSection<long>, WadLogDownloadedSection>()
                .ForMember(d => d.StartKey, f => f.MapFrom(s => s.StartIndex))
                .ForMember(d => d.EndKey, f => f.MapFrom(s => s.EndIndex));
            mapper.CreateMap<LoadedRangeSection<long>, WadLogDownloadedSection>()
                .ForMember(d => d.StartKey, f => f.MapFrom(s => s.StartIndex))
                .ForMember(d => d.EndKey, f => f.MapFrom(s => s.EndIndex));
            mapper.CreateMap<WadLogDownloadedSectionDto, WadLogDownloadedSection>();
            mapper.CreateMap<WadLogDownloadedSectionDto, FragmentedRangeSection<long>>()
                .ForMember(d => d.StartIndex, f => f.MapFrom(s => s.StartKey))
                .ForMember(d => d.EndIndex, f => f.MapFrom(s => s.EndKey));
            mapper.CreateMap<WadLogDownloadedSectionDto, LoadedRangeSection<long>>()
                .ForMember(d => d.StartIndex, f => f.MapFrom(s => s.StartKey))
                .ForMember(d => d.EndIndex, f => f.MapFrom(s => s.EndKey));
        }

        #endregion
    }
}
